/**
 * 
 */
package com.feib.stms.dao.jdbc.rowmapper;

import java.sql.ResultSet;

import org.springframework.jdbc.core.RowMapper;

import com.feib.stms.model.Group;
import com.feib.stms.model.Securities;
import com.feib.stms.model.User;
import com.feib.stms.model.UserLoginControl;

/**
 * @author Jimmy Liu
 *
 */
public class UserRowMapper extends BaseRowMapper<User> implements RowMapper<User> 
{
	private static final long serialVersionUID = -8892893264359339120L;
	
	public UserRowMapper() 
	{
		super(User.class);
	}

	@Override
	protected User doOtherMapRow(ResultSet rs, int rowNumber, User entity) 
	{
		entity.setEnabled(getColumnBoolean(rs, "IS_ENABLED"));
		entity.setLocked(getColumnBoolean(rs, "IS_LOCKED"));
		
		entity.setSecurities(new Securities());
		entity.getSecurities().setSecuritiesPk((Long)getColumnValue(rs, "SECURITIES_PK", Long.class));
		entity.getSecurities().setSecuritiesNo((String)getColumnValue(rs, "SECURITIES_NO", String.class));
		entity.getSecurities().setSecuritiesName((String)getColumnValue(rs, "SECURITIES_NAME", String.class));
		
		entity.setGroup(new Group());
		entity.getGroup().setGroupPk((Long)getColumnValue(rs, "GROUP_PK", Long.class));
		entity.getGroup().setGroupNo((String)getColumnValue(rs, "GROUP_NO", String.class));
		entity.getGroup().setGroupName((String)getColumnValue(rs, "GROUP_NAME", String.class));

		entity.getGroup().setGroupType((Integer)getColumnValue(rs, "GROUP_TYPE", Integer.class));
		entity.getGroup().setGroupNote((String)getColumnValue(rs, "GROUP_NOTE", String.class));
		entity.getGroup().setContactName((String)getColumnValue(rs, "CONTACT_NAME", String.class));
		entity.getGroup().setContactEmail((String)getColumnValue(rs, "CONTACT_EMAIL", String.class));
		entity.getGroup().setContactTelno((String)getColumnValue(rs, "CONTACT_TELNO", String.class));
		entity.getGroup().setContactCellno((String)getColumnValue(rs, "CONTACT_CELLNO", String.class));
		entity.getGroup().setGroupAddress((String)getColumnValue(rs, "GROUP_ADDRESS", String.class));
		entity.getGroup().setUbm((String)getColumnValue(rs, "UBM", String.class));
		entity.setUserLoginControl(new UserLoginControl());
		entity.getUserLoginControl().setActived(getColumnValue(rs, "IS_ACTIVED", Integer.class)==null?false:(Integer)getColumnValue(rs, "IS_ACTIVED", Integer.class)>0);
		return entity;
	}

}